package com.woniuxy.movie.gateway.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;

import java.util.List;

@Data
@Component
@ConfigurationProperties(prefix = "urls")
public class AuthenUrlProperties {

    //公共资源
    private List<String> baseUrls;

    //管理端公开资源
    private List<String> adminUrls;

    //用户端公开资源
    private List<String> userUrls;

    AntPathMatcher match = new AntPathMatcher();

    /**
     * 比较管理端公开资源是否匹配
     */
    public boolean matchAdmin(String path){
        if (adminUrls == null || adminUrls.size() == 0) return false;
        for (String s : adminUrls) {
            if (match.match(s,path)) return true;
        }
        return false;
    }

    /**
     * 比较用户端公开资源是否匹配
     */
    public boolean matchUser(String path){
        if (userUrls == null || userUrls.size() == 0) return false;
        for (String s : userUrls) {
            if (match.match(s,path)) return true;
        }
        return false;
    }


}
